package ssm.integration.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * description: 业务层配置类-02
 * TODO: service, aop, tx
 *
 * 1. @Configuration 声明配置类
 * 2. @ComponentScan("") 类路径扫描，将 Service 添加到IOC容器
 * 3. @EnableAspectJAutoProxy 开启AOP注解支持（@Before @After @AfterReturning @AfterThrowing @Around  @Aspect @Order）
 * 4. @EnableTransactionManagement 开启事务注解支持（@Transactional）
 * 5. 事务管理器 `DataSourceTransactionManager` 整合了Mybatis方式事务管理器实现
 * 6. @Bean 将事务管理器注入IOC容器
 */

@Configuration
@EnableAspectJAutoProxy
@EnableTransactionManagement
@ComponentScan("ssm.integration.service")
public class ServiceJavaConfig {

    //事务操作JDBC实现类，需要连接池对数据库进行事务操作
    @Bean
    public TransactionManager transactionManager(DataSource dataSource){
        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
        dataSourceTransactionManager.setDataSource(dataSource);
        return dataSourceTransactionManager;
    }
}
